package com.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * 拦截器
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Resource
    LoginInterceptor loginInterceptor;

//    拦截器开关
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//
//        InterceptorRegistration interceptorRegistration = registry.addInterceptor(loginInterceptor);
//
////                registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**")
////                .excludePathPatterns("/login","/index","/managerLogin","/","/css/*","/images/*","/js/*");//不会被拦截的目录
////        /*代表拦截一级目录，/test/a不会被拦截; /**代表拦截所有请求 /只拦截根目录，即localhost:8080
//
//        interceptorRegistration.addPathPatterns("/**");
//
//        interceptorRegistration.excludePathPatterns(
//                "/",
//                "/*",
//                "/aaa",
//                "/ss",
//                "/ssh",
//
//                "/shen",
//                "/css/*",
//                "/images/*",
//                "/js/*",
//
//                "/register_verify",
//                "/register",
//                "/verify",
//                "/password_verify",
//                "/login",
//                "/reLogin",
//
//                "/getAdminImage",
//                "/getAdminName"
//        );
//
//        interceptorRegistration.excludePathPatterns(
//                "/Ajax.html",
//                "/detailsMod.html",
//                "/details.html",
//                "/index.html",
//                "/list.html",
//                "/login.html",
//                "/manager.html",
//                "/managerLogin.html",
//                "/Mod.html",
//                "/shopCar.html",
//                "/shoppCar2.html",
//                "/up.html",
//                "/upload.html"
//        );
//
//        interceptorRegistration.excludePathPatterns("/templates");
//        interceptorRegistration.excludePathPatterns("/templates/images");
//        interceptorRegistration.excludePathPatterns("/js/*","/css/*","/images/*.jpg","/images/*.png","/","/*");
//        interceptorRegistration.excludePathPatterns("/css/external/*.css");
//        interceptorRegistration.excludePathPatterns("/js/external/*.js");
//        interceptorRegistration.excludePathPatterns("/images/*.jpg");
//        interceptorRegistration.excludePathPatterns("/images/*.png");
//        interceptorRegistration.excludePathPatterns("/css/*.css","/css/external","/css/index","/modules");
//        interceptorRegistration.excludePathPatterns("/resources/images/");
//        interceptorRegistration.excludePathPatterns("/css/*","/css/external/*","/css/index/*","/css/modules/*","/images/*","/images/img/*.jpg","/images/img/*.png","/images/indexImg/*.png");
//    }


//保护机制
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//            配置静态资源映射,访问images就会找绝对路径
            registry.addResourceHandler("/static/images/**").addResourceLocations("file:/summer/src/main/resources/static/images/");
            registry.addResourceHandler("/static/images/**").addResourceLocations("file:/summer/src/main/resources/static/images/product");
            registry.addResourceHandler("/static/images/**").addResourceLocations("file:D:\\桌面\\夏日速递2.0\\summer2.0\\summer\\src\\main\\resources\\static\\images\\");
    }
}

